<template>
  <div>
    <el-upload
      class="importPrice"
      ref="upload"
      action="/api/dmscloud.sysbasedata/vehicleProduct/car/importCarPrice"
      :limit="2"
      :headers="headersObj"
      :on-success="showErrorList"
      :on-exceed="handleExceed">

      <el-button size="small" type="primary">点击上传</el-button>
    </el-upload>
    <div style="text-align: center;margin: 10px;">
      <el-button size="small" @click="cancle" type="">返回</el-button>
      <el-button size="small" @click="saveHandle" type="primary">保存</el-button>
    </div>
    <FilterTable
      ref="table"
      :columns="columns"
      :dataSource="errorList"
      :datakey="'records'"
      :isSelectColumn="false"
      :onColumnsChange="columns => this.columns = columns"
      style="margin-top: 10px"
    >
    </FilterTable>

  </div>
</template>
<script>
import {
  importCarPrice
 } from '@/api/common/cars/masterDataCars';
import { dictionary } from '@/utils/dictMixin';
import { getToken, getAppId } from '@/assets/js/auth';

export default {
  name: 'importPricePanel',
  mixins: [dictionary],
  data(){
    return {
      columns: this.createTableColumns(),
      headersObj: {
        jwt: getToken(),
        appId: getAppId(),
        userAgent: 'pc'
      },
      errorList: [],
      isUpload:false,
    }
  },
  methods: {
    createTableColumns(){
      return [
        {
          title: '序号',
          dataIndex: 'index',
          align: 'center',
          width: 70,
          fixed: 'left',
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '行号',
          dataIndex: 'rowNO',
          filterType: 'input'
        },
        {
          title: '产品代码',
          dataIndex: 'productCode',
          filterType: 'input'
        },
        {
          title: '错误原因',
          dataIndex: 'errorMsg',
          filterType: 'input'
        }
      ]
    },
    showErrorList(response, file, fileList){
      console.log(response,"response")
      if(response.data){
        this.errorList = response.data;
        this.$message("上传成功!  "+this.errorList.length+"条处理失败");
         this.isUpload = true
      }else{
        this.$message(`${response.errMsg}`);
      }
      // this.cancle()
    },
    handleExceed(files, fileList){
      console.log(11111)
      this.$message(`只能选择一个文件`);
    },

    saveHandle(){
      if(this.isUpload){
        this.cancle()
      }
    },
    cancle(){
      this.$emit("close")
    }
  }
}
</script>
